package TestCode;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class Main {
    public static void main(String[] args) throws IOException {
        //定义文件位置
        String resource = "mybatis-config.xml";
        //获取输入流
        InputStream inputStream = Resources.getResourceAsStream(resource);
        //基于配置文件构建工厂SqlSessionFactory
        SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        //打开session
        try (SqlSession session = sessionFactory.openSession()) {
        //根据id查找sql面板，返回查询结果
            List<Student> students = session.selectList("student");
            students.forEach(System.out::println);
        }
    }
}
